<?php

namespace catchAdmin\basics\controller;

use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\basics\model\Follow as FollowModel;
use think\Response;
use catcher\CatchAuth;
use think\facade\Db;

class Follow extends CatchController
{
    
    protected $followModel;
    
    /**
     *
     * @time 2022/06/09 13:45
     * @param FollowModel $followModel
     * @return mixed
     */
    public function __construct(FollowModel $followModel)
    {
        $this->followModel = $followModel;
    }
    
    /**
     *
     * @time 2022/06/09 13:45
     * @param Request $request
     * @return Response
     */
    public function index(CatchAuth $auth,Request $request)
    {
        $params = $request->filterEmptyField()->post();
        $user = $auth->user();
        return CatchResponse::paginate($this->followModel->getList($user['tenant_id'],$params['pid']));
    }

    /**
     *
     * @time 2022/02/15 11:41
     * @param Request $request
     * @return \think\response\Json
     */
    public function create(CatchAuth $auth,Request $request)
    {
        $params = $request->filterEmptyField()->post();
        $user = $auth->user();
        $params['tenant_id'] = $user['tenant_id'];
        return CatchResponse::success($this->followModel->storeBy($params),"新建成功");
    }

    /**
     *
     * @time 2022/06/09 13:45
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update(Request $request)
    {
        $params = $request->filterEmptyField()->post();
        return CatchResponse::success($this->followModel->updateBy($params['id'], $params),"修改成功");
    }
    
    /**
     *
     * @time 2022/06/09 13:45
     * @param $id
     * @return Response
     */
    public function delete($id) : Response
    {
        return CatchResponse::success($this->followModel->deleteBy($id));
    }
    /**
     *
     * @time 2022/02/15 11:41
     * @param Request $request
     * @return \think\response\Json
     */
    public function getFollow(CatchAuth $auth,Request $request)
    {
        $params = $request->filterEmptyField()->post();
        $user = $auth->user();
        $where = [];
        $where[] = ['deleted_at','=',0];
        $where[] = ['pid','=',$params['pid']];
        $data = Db::table('db_follow')->where($where)->select();
        return CatchResponse::success($data,"获取成功");
    }
}